home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / PeopleDemo_oracle / Department.m < prev    next >
Text File  |  1994-06-23  |  2KB  |  129 lines

  1. /* Department.m
  2.  * A simple enterprise object.
  3.  * 
  4.  * You may freely copy, distribute, and reuse the code in this example.
  5.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  6.  * fitness for any particular use.
  7.  *
  8.  * Written by Mai Nguyen, NeXT Developer Support
  9.  */
  10.  
  11. #import "Department.h"
  12. #import "strings.h"
  13.  
  14.  
  15. @implementation Department
  16.  
  17. - init 
  18. {
  19.     /* You can add additional intialization here. */
  20.     [super init];
  21.     return self;
  22. }
  23.  
  24. /* DEBUGGING METHODS */
  25.  
  26. - (BOOL)respondsTo:(SEL)sel
  27. {
  28. #ifdef DEBUG      
  29.     fprintf(stderr, "RespondsTo: %s\n", sel_getName(sel));
  30. #endif
  31.     return [super respondsTo:sel];
  32. }
  33.  
  34.  
  35. /* Accessor methods */
  36.  
  37. - (void) setDeptId:(NSNumber *)newId
  38. {
  39.     [DeptId release];
  40.     DeptId = [newId retain];
  41.      
  42.  
  43. - (void) setDepartmentName:(NSString *)newName
  44. {
  45.     [DepartmentName release];
  46.     DepartmentName = [newName retain];
  47.      
  48. }
  49.  
  50. - (void) setLocationId:(NSNumber *)newLocation
  51. {
  52.     [LocationId release];
  53.     LocationId = [newLocation retain];
  54.      
  55.  
  56. - (NSArray *) toEmployee
  57. {
  58.     return toEmployee;
  59. }
  60.  
  61. - (void) setToEmployee:(NSArray *)aRelation
  62. {
  63.     [toEmployee release];
  64.     toEmployee = [aRelation retain];
  65.      
  66. }
  67.  
  68. - (void) setAverageSalary:(NSNumber *)aSalary
  69. {
  70.     [averageSalary release];
  71.     averageSalary = [aSalary retain];
  72.      
  73. }
  74.  
  75. - (NSNumber *)averageSalary
  76. {
  77.     int            i;
  78.     unsigned    count = 0;
  79.     id            anEmployee, value;
  80.     int         totalSalaries = 0;
  81.     
  82.     if (toEmployee) {
  83.         count = [toEmployee count];
  84.         totalSalaries = 0;
  85.         for (i = 0; i < count; i++) {
  86.             anEmployee = [toEmployee objectAtIndex:i];
  87.             value = [anEmployee objectForKey:@"Salary"];
  88.                 /* skip Salary with Null values */
  89.             if  (![value isEqual:[EONull null]])
  90.             totalSalaries += [[anEmployee objectForKey:@"Salary"] intValue];
  91.             } 
  92.     }
  93.     if (count > 0)
  94.          avgSalaries = totalSalaries/count;     
  95.     return [NSNumber numberWithInt:avgSalaries];    
  96.         
  97. }
  98.  
  99.  
  100. /* This method is just a place holder.  Do not call [super dealloc].
  101.  * Do nothing.
  102.  */
  103. - (void)dealloc
  104. {
  105.    
  106. }
  107.  
  108. - free
  109. {
  110.    /* Free our ivars, and do all the normal cleanup... */
  111.      [DeptId release];
  112.      [DepartmentName release];
  113.      [LocationId release];
  114.      [FacilityLocation release];
  115.      [toEmployee release];
  116.      [averageSalary release];   
  117.  
  118.     /* Send ourselves a dealloc message so we will be removed
  119.      *from the uniquing tables.
  120.      */
  121.     [self dealloc];
  122.  
  123.     return [super free];
  124. }
  125.  
  126. @end
  127.